<?php
/*
 * Created on Feb 12, 2008
 *
 * Donald J. Ankney
 * Academic Personnel Information Services
 * ankneyd@u.washington.edu
 *
 * Class is a REST webservice client
 * can use SSL
 *
 */


class RestClient {
        public $certPath;
        public $keyPath;
        public $uriBase;

        // Method pulls the resource via curl and returns a string of the resource
        function getResource ($uri) {
                $ch = curl_init($this->uriBase.$uri);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                //TODO: VERIFYPEER is necessary for enterprise use, implement some rules around it
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                if ($this->keyPath AND $this->certPath) { // if cert/key attributes are set, use them
                        curl_setopt($ch, CURLOPT_SSLCERT, $this->certPath);
                        curl_setopt($ch, CURLOPT_SSLKEY, $this->keyPath);
                }

                $resource=curl_exec($ch);
                $info = curl_getinfo($ch);
                if ($info1 != '200') {
                        //TODO: Better error handling
                        return FALSE;
                };
                curl_close($ch);
                return $resource;
        }
}

$webQ = new RestClient();
$webQ->uriBase = 'https://catalysttools.washington.edu/rest/webq/v1';
$webQ->certPath = '/Path/to/cert.pem';
$webQ->keyPath = '/Path/to/key.pem';

$result = $webQ->getResource("/survey/number");//Or whatever you need do construct to pull the data
if ($result)
{
    //Do something with the resource
}
else
{
        //TODO: Better error handling
        echo "ERROR: http transfer problem";
}